package parabullgame;

import java.awt.Color;
import java.util.ArrayList;

public class GuiControlBase {

    public int posX;
    public int posY;
    public int width;
    public int height;
    public GuiControlBase parent;
    public ArrayList<GuiControlBase> children;
    public Color color;
    
    public GuiControlBase(int x, int y, int w, int h) {
        posX = x;
        posY = y;
        width = w;
        height = h;
        
        color = Color.DARK_GRAY;
        children = new ArrayList<GuiControlBase>();
    }

    public void addChild(GuiControlBase child) {
        children.add(child);
        child.parent = this;
    }

    public void draw(int offsetX, int offsetY) {
    }

    public final void drawInternal(int offsetX, int offsetY) {
        offsetX += posX;
        offsetY += posY;
        draw(offsetX, offsetY);
        for (GuiControlBase child : children) {
            child.drawInternal(offsetX, offsetY);
        }
    }

    public void mouseClick(int button, boolean pressed, int x, int y) {
    }

    public final boolean mouseClickInternal(int button, boolean pressed, int x, int y) {
        if (posX < x && x < posX + width && posY < y && y < posY + height) {
            x -= posX;
            y -= posY;
            for (GuiControlBase child : children) {
                if (child.mouseClickInternal(button, pressed, x, y)) {
                    return true;
                }
            }

            mouseClick(button, pressed, x, y);
            return true;
        }
        return false;
    }

    public void think(int mouseX, int mouseY) {
    }

    public final void thinkInternal(int mouseX, int mouseY) {
        mouseX -= posX;
        mouseY -= posY;

        for (GuiControlBase child : children) {
            child.thinkInternal(mouseX, mouseY);
        }

        think(mouseX, mouseY);
    }
}